<%--
 * (c)2010-2012 Andrea Caltroni (andrea.caltroni@pd.infn.it), INFN (www.infn.it)
 *
 * This file is part of the IGI Survey Portlet (from here on shortened to IGISP).
 * IGISP is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) any 
 * later version.
 *
 * IGISP is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IGISP. If not, see <http://www.gnu.org/licenses/>.
 *
--%>

<%@ include file="./init.jsp" %>

<% pageContext.setAttribute("newLineChar", "\n"); %>
<% pageContext.setAttribute("newLineHtml", "<br />"); %>

<c:set var="numAnswers" value="${fn:length(question.answers)}" />

<h3><spring:message code="questionAnswers.view.title"/></h3>
<table class="lfr-table">
    <tr>
        <th><spring:message code="survey.label.survey"/>:</th>
        <td><a href="<portlet:renderURL><portlet:param name="action" value="viewSurvey"/><portlet:param name="surveyID" value="${question.survey.id}"/></portlet:renderURL>">${question.survey.name}</a></td>
    </tr>
    <tr>
        <th><spring:message code="survey.label.question"/> (${question.position}):</th>
        <td><c:out value="${fn:replace(question.description, newLineChar, newLineHtml)}" escapeXml="false" /></td>
    </tr>
</table>
<%--
<h4>
    <spring:message code="survey.label.survey"/>: ${question.survey.name}&nbsp;
    <a href="<portlet:renderURL><portlet:param name="action" value="viewSurvey"/><portlet:param name="survey" value="${question.survey.id}"/></portlet:renderURL>"><img title="<spring:message code="survey.view.button"/>" src="<html:imagesPath/>view.png" border=0 /></a>
</h4>
<h4>
    <spring:message code="survey.label.question"/>: ${question.description}&nbsp;
    <a href="<portlet:renderURL><portlet:param name="action" value="viewSurveyQuestions"/><portlet:param name="survey" value="${question.survey.id}"/></portlet:renderURL>"><img title="<spring:message code="surveyQuestions.view.button"/>" src="<html:imagesPath/>view.png" border=0 /></a>
</h4>
--%>
<div class="lfr-separator">&nbsp;</div>

<div class="portlet-body">

    <table class="lfr-table">
<c:choose><c:when test="${numAnswers <= 0}">
        <tr>
            <td colspan="3"><spring:message code="survey.label.noAnswers"/></td>
        </tr>
</c:when>
<c:otherwise>
        <tr>
            <th><spring:message code="answer.label.position"/></th>
            <th><spring:message code="answer.label.description"/></th>
            <th><spring:message code="answer.label.answerMode"/></th>
            <th><spring:message code="answer.label.counter"/></th>
            <th><spring:message code="answer.label.skipToQuestion"/></th>
            <th>&nbsp;</th>
        </tr>
    <c:forEach var="answer" items="${question.answers}">
        <tr>
            <td>${answer.position}</td>
            <td><c:out value="${fn:replace(answer.description, newLineChar, newLineHtml)}" escapeXml="false" /></td>
            <td>${answer.answerMode.translatedName}</td>
            <td>
        <c:choose>
            <c:when test="${answer.answerMode == 'CUSTOM_DESC' && answerVotes[answer.position] > 0}" >
                <a href="<portlet:renderURL>
                <portlet:param name="action" value="viewCustomDescriptions"/>
                <portlet:param name="answerID" value="${answer.id}"/>
                <portlet:param name="pagedListHolder" value="null"/>
                <portlet:param name="p" value="0"/>
                </portlet:renderURL>">${answerVotes[answer.position]}</a>
            </c:when>
            <c:otherwise>
                ${answerVotes[answer.position]}
            </c:otherwise>
        </c:choose>
            </td>
            <td>${answer.skipToQuestion.position}</td>
            <td>
                <a href="<portlet:renderURL><portlet:param name="action" value="showEditAnswerForm"/><portlet:param name="questionID" value="${question.id}"/><portlet:param name="answerID" value="${answer.id}"/></portlet:renderURL>"><img title="<spring:message code="answer.edit.button"/>" src="<html:imagesPath/>edit.png" border=0 /></a>&nbsp;
                <a href="<portlet:actionURL>
                            <portlet:param name="action" value="deleteAnswer"/>
                            <portlet:param name="answerID" value="${answer.id}"/>
                         </portlet:actionURL>
                         " onclick="return confirm('<spring:message code="message.confirm.delete.answer"/>')">
                         <img title="<spring:message code="answer.delete.button"/>" src="<html:imagesPath/>delete.png" border=0 />
                </a>
            </td>
        </tr>
    </c:forEach>
</c:otherwise></c:choose>
    </table>

</div>

<div class="lfr-separator">&nbsp;</div>

<div class="lfr-toolbar">
<c:if test="${question.answersType != 'SINGLE_ANSWER'}" >
    <a href="<portlet:renderURL><portlet:param name="action" value="showAddAnswerForm"/><portlet:param name="questionID" value="${question.id}"/></portlet:renderURL>"><img title="<spring:message code="answer.add.button"/>" src="<html:imagesPath/>new.png" border=0 /></a>&nbsp;&nbsp;
</c:if>
    <a href="<portlet:renderURL><portlet:param name="action" value="showChangeAnswerOrderForm"/><portlet:param name="questionID" value="${question.id}"/></portlet:renderURL>"><img title="<spring:message code="questionAnswers.changeOrder.button"/>" src="<html:imagesPath/>change-order.png" border=0 /></a>&nbsp;
    <a href="<portlet:renderURL><portlet:param name="action" value="viewSurveyQuestions"/><portlet:param name="surveyID" value="${question.survey.id}"/></portlet:renderURL>"><img title="<spring:message code="surveyQuestions.view.button"/>" src="<html:imagesPath/>view-questions.png" border=0 /></a>&nbsp;
    <a href="<portlet:renderURL portletMode="view"/>"><img title="<spring:message code="button.home"/>" src="<html:imagesPath/>home.png" border=0 /></a>
</div>
